/* dsdw.t - INTERSITE REQUEST WRITE TRIGGER                                   */
/*Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                         */
/*All rights reserved worldwide.  This is an unpublished work.                */
/*V8:ConvertMode=NoConvert                                                    */
/******************************************************************************/
/*  !Description : dsd_det WRITE trigger program                              */
/*          : In order to enhance this trigger to support additional          */
/*          : interfaces, add a DO-END block similar to the one used for the  */
/*          : Warehousing Interface to (1) check for the need to continue     */
/*          : processing; (2) move the relevant fields to an appropirate      */
/*          : work area; and (3) call one or more subprograms to continue     */
/*          : processing. This .t program should remain short, relying on     */
/*          : subprograms to perform most of the work.                        */
/******************************************************************************/
/*                              MODIFY LOG                                    */
/******************************************************************************/
/* Revision 8.5          Last Modified:  03/14/96 BY: BHolmes *J0FY*          */
/* Revision 8.5          Last Modified:  07/27/96 BY: fwy     *J12B*          */
/* Revision 8.5          Last Modified:  01/07/97 BY: jpm     *J1DM*          */
/* Revision 9.1          Last Modified:  08/14/00 BY: *N0KW* Jacolyn Neder    */
/* $Revision: 1.4 $     BY: Jean Miller          DATE: 08/16/02  ECO: *P0FN*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

TRIGGER PROCEDURE FOR WRITE OF DSD_DET OLD BUFFER OLD_DSD_DET.

{mfdeclre.i }

define new shared work-table wf_old_dsd_det like dsd_det.
define new shared variable w-recid as recid.
define variable w-file as character format "x(24)".
define new shared variable w-site-loc-id like whl_mstr.whl_src_dest_id.
define new shared variable w-site like so_site.
define new shared variable w-loc  like loc_loc.

/* Warehousing Interface processing */
WI:
do:

   /* If there is no active external warehouse that is flagged to
      receive intersite request export transactions, then do not process */
   if not can-find(first whl_mstr no-lock
                   where whl_mstr.whl_act and
                         whl_mstr.whl_do_req_exp)
   then leave WI.

   /* If no pertinent fields have been changed, then do not process */
   if (old_dsd_det.dsd_nbr      = dsd_det.dsd_nbr and
       old_dsd_det.dsd_req_nbr  = dsd_det.dsd_req_nbr and
       old_dsd_det.dsd_part     = dsd_det.dsd_part and
       old_dsd_det.dsd_rev      = dsd_det.dsd_rev
      and old_dsd_det.dsd_site     = dsd_det.dsd_site
      and old_dsd_det.dsd_loc      = dsd_det.dsd_loc
      and old_dsd_det.dsd_shipsite = dsd_det.dsd_shipsite
      and old_dsd_det.dsd_qty_conf = dsd_det.dsd_qty_conf
      and old_dsd_det.dsd_trans_id = dsd_det.dsd_trans_id
      and old_dsd_det.dsd_due_date = dsd_det.dsd_due_date
      and old_dsd_det.dsd_rmks     = dsd_det.dsd_rmks
      and old_dsd_det.dsd_user1    = dsd_det.dsd_user1
      and old_dsd_det.dsd_user2    = dsd_det.dsd_user2
      and old_dsd_det.dsd_cmtindx  = dsd_det.dsd_cmtindx)
   then leave WI.

   /* Move old dsd_det values to work table for subsequent processing */
   assign w-recid = recid(dsd_det).

   create wf_old_dsd_det.

   if recid(wf_old_dsd_det)= -1 then .

   assign
      wf_old_dsd_det.dsd_nbr       = old_dsd_det.dsd_nbr
      wf_old_dsd_det.dsd_req_nbr   = old_dsd_det.dsd_req_nbr
      wf_old_dsd_det.dsd_part      = old_dsd_det.dsd_part
      wf_old_dsd_det.dsd_rev       = old_dsd_det.dsd_rev
      wf_old_dsd_det.dsd_site      = old_dsd_det.dsd_site
      wf_old_dsd_det.dsd_loc       = old_dsd_det.dsd_loc
      wf_old_dsd_det.dsd_shipsite  = old_dsd_det.dsd_shipsite
      wf_old_dsd_det.dsd_qty_conf  = old_dsd_det.dsd_qty_conf
      wf_old_dsd_det.dsd_trans_id  = old_dsd_det.dsd_trans_id
      wf_old_dsd_det.dsd_due_date  = old_dsd_det.dsd_due_date
      wf_old_dsd_det.dsd_rmks      = old_dsd_det.dsd_rmks
      wf_old_dsd_det.dsd_user1     = old_dsd_det.dsd_user1
      wf_old_dsd_det.dsd_user2     = old_dsd_det.dsd_user2
      wf_old_dsd_det.dsd_cmtindx   = old_dsd_det.dsd_cmtindx.

   /* Call appropriate subprogram to create export transactions */
   /* If distribution order number has been attached to intersite request,
      create an add transaction */
   if dsd_det.dsd_nbr ne ""
   then do:

      w-file = "widsdw.p".
      {gprunmo.i &module="WI"
                 &program="widsdw.p"}
   end.

   /* If distribution order number has been removed from intersite request,
     create a delete transaction */
   if dsd_det.dsd_nbr = "" and
      wf_old_dsd_det.dsd_nbr = ""
   then do:
      w-file = "widsdd.p".
      {gprunmo.i &module="WI"
                 &program="widsdd.p"}
   end.

end. /* WI */

/* Track Capacity Units */
if dsd_det.dsd_status <> "" then do:

   /* Get the New Intersite Requests */
   if (new dsd_det and
       (old_dsd_det.dsd_site  <> dsd_det.dsd_site  or
        old_dsd_det.dsd_req_nbr <> dsd_det.dsd_req_nbr or
        old_dsd_det.dsd_shipsite <> dsd_det.dsd_shipsite)) or
   /* Get the Previously Planned Intersite Requests */
      (not new dsd_det and
      (old_dsd_det.dsd_status <> dsd_det.dsd_status) and
      (old_dsd_det.dsd_status = "P"))
   then do:
      {lvucap.i &TABLE="dsd_det" &QUALIFIER="dsd_det.dsd_status"}
   end.

end.
